/*
 * BangoConstants.cpp
 *

 */
#include "BangoConstants.h"

BangoConstants *BangoConstants::_instance = 0;

BangoConstants* BangoConstants::GetInstance(void)
{
	static QMutex mutex;
	if(!_instance){
		mutex.lock();
		if(!_instance){
			_instance = new BangoConstants();
			atexit(doCleanup);
			mutex.unlock();
		}
	}
	return _instance;

}

void BangoConstants::doCleanup(void)
{
	static QMutex mutex;
	if(_instance != NULL){
		mutex.lock();
		delete _instance;
		_instance = 0;
		mutex.unlock();
	}
}

//integral types

	BangoConstants::BangoConstants()
	{
			SDK_TYPE = 12;

			POSTDELAY_SESSIONEND = 10000L;

			WIFI_CONNECTION = -999;
			OPERATOR_CONNECTION = 0;
			UNKNOWN_CONNECTION = -1;
			LOCATION_MANAGER_MIN_TIME = 0L;
			LOCATION_MANAGER_MIN_DISTANCE = 0.0f;

			ERROR_NONE = 0;
			ERROR_USER = 1;
			ERROR_INTERNAL_CRITICAL = -1;
			ERROR_INTERNAL_WARNING = -2;
			SETTING_USEOFFLINESTORAGE = true;
			SETTING_FINDLOCATION = true;
			SETTING_LOGEVENTS = true;
			SETTING_SESSION_RESUME_PERIOD = 10;
			SETTING_PERSIST_DATABASE_CONNECTION = false;
			SETTING_MAXIMUM_EVENTS_PER_PROFILE = 50;
			SETTING_LOCATION_FIND = true;

			//non-integral types
			SDK_VERSION = "1.1.1";

			POST_RESPONSE_SUCCESS = "OK";
			ERROR_TAG = "BANGO_INAPP_ANALYTICS";

			VIDEO_PARAMETERNAME = "BGO_VIDEOTYPE";
			VIDEO_LIVEPARAMETER = "LIVE";
			VIDEO_ONDEMANDPARAMETER = "ONDEMAND";

			OPTION_OTHER = "OTHER";
			UNKNOWN_VERSION = "Unknown";
			UNKNOWN_INFORMATION = "Unknown";

			POSITIONINGMETHOD_ALLPOSITIONINGMETHODS = "AllPositioningMethods";
			POSITIONINGMETHOD_NONSATELLITEPOSITION = "NonSatellitePosition";
			POSITIONINGMETHOD_SATELLITEPOSITION = "SatellitePosition";
			LOCATION_CELL = "CELL";
			LOCATION_ASSISTED = "ASSISTED";
			LOCATION_GPS = "GPS";



			SETTING_POST_URL = "https://a.bango.net/AppAnalytics/";
			SETTING_LOCATION_SOURCE = LOCATION_GPS;

			DATETIME_FORMAT = "yyyy-MM-dd hh:mm:ss.zzz";

			DATABASE_NAME = "BangoAnalytics.sqlite";
			DATABASE_VERSION = 1;
			DATABASE_TABLE_PLACEHOLDER = "$TABLENAME";
			DATABASE_TABLE_JOINPLACEHOLDER = "$TABLEJOINNAME";
			DATABASE_PARAMETER1_PLACEHOLDER = "$PARAMETER1";
			DATABASE_PARAMETER2_PLACEHOLDER = "$PARAMETER2";
			DATABASE_PARAMETER3_PLACEHOLDER = "$PARAMETER3";
			DATABASE_PARAMETER4_PLACEHOLDER = "$PARAMETER4";
			DATABASE_PARAMETER5_PLACEHOLDER = "$PARAMETER5";

			DATABASE_TABLENAMEPREFIX = "InApp";

			DATABASE_SELECTTABLES = "SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '" + DATABASE_TABLENAMEPREFIX + "'%'";
			DATABASE_SELECTPOSTPROFILES = "SELECT _id as profileId, sdkType, sdkVersion, applicationId, applicationType, applicationChannel, applicationVersion, userId, sessionRestartTime, connectionType, isRoaming, locationSource, locationAltitude, locationLatitude, locationLongitude, locationAccuracy, operator, operatorName, operatorCountryIso, simOperator, simCardSerial, device, model, hardwareId, version, pin, operatorConnectionType FROM [$TABLENAME] WHERE _id != :id";
			DATABASE_SELECTPOSTEVENTS = "SELECT _id as eventId, profileId, eventName, eventDetail, eventValue, errorId, eventTime, eventLocalTime, connectionType, operatorConnectionType, errorLevel FROM [$TABLENAME] WHERE eventPosted = 0 AND profileId = :id";
			DATABASE_SELECTPOSTEVENTPARAMETERS = "SELECT _id as eventParameterId, eventId, eventName, eventValue FROM [$TABLENAME] WHERE eventId = :id";

			DATABASE_UPDATEPROFILELOCATION = "UPDATE [$TABLENAME] SET locationLatitude = :locationLatitude, locationLongitude = :locationLongitude, locationAltitude = :locationAltitude, locationAccuracy = :locationAccuracy, locationSource = :locationSource WHERE _id = :id ";
			DATABASE_UPDATEPROFILEPOSTED = "UPDATE [$TABLENAME] SET profilePosted = 1 WHERE _id = ";
			DATABASE_UPDATEEVENTPOSTED = "UPDATE [$TABLENAME] SET eventPosted = 1 WHERE profileId = ";

			DATABASE_DELETEPROFILE = "DELETE FROM [$TABLENAME] WHERE profilePosted = 1 AND _id = ";
			DATABASE_DELETEEVENT = "DELETE FROM [$TABLENAME] WHERE eventPosted = 1 AND profileId = ";
			DATABASE_DELETEEVENTPARAMETER = "DELETE FROM [$TABLENAME] WHERE eventId IN (SELECT _id FROM [$TABLEJOINNAME] WHERE eventPosted = 1 AND profileId = $PARAMETER1)";

			DATABASE_DELETEORPHANEVENTPARAMETER = "DELETE FROM [$TABLENAME] WHERE eventId NOT IN (SELECT _id FROM [$TABLEJOINNAME])";
			DATABASE_DELETEORPHANEVENT = "DELETE FROM [$TABLENAME] WHERE profileId NOT IN (SELECT _id FROM [$TABLEJOINNAME])";

			DATABASE_TABLECREATEPROFILE = "CREATE TABLE IF NOT EXISTS [$TABLENAME] (_id INTEGER PRIMARY KEY, sdkType INTEGER, sdkVersion TEXT, applicationId TEXT, applicationType TEXT, applicationChannel TEXT, applicationVersion TEXT, userId TEXT, sessionRestartTime INTEGER, connectionType INTEGER, isRoaming BOOLEAN, locationSource TEXT, locationAltitude NUMERIC, locationLatitude NUMERIC, locationLongitude NUMERIC, locationAccuracy NUMERIC, operator TEXT, operatorName TEXT, operatorCountryIso TEXT, simOperator TEXT, simCardSerial TEXT, device TEXT, model TEXT, hardwareId TEXT, version TEXT, pin TEXT, operatorConnectionType INTEGER, profilePosted BOOLEAN)";
			DATABASE_TABLECREATEEVENT = "CREATE TABLE IF NOT EXISTS [$TABLENAME] (_id INTEGER PRIMARY KEY, profileId INTEGER, eventName TEXT, eventDetail TEXT, eventValue TEXT, errorId TEXT, eventTime TEXT, eventLocalTime TEXT, connectionType INTEGER, operatorConnectionType INTEGER, errorLevel INTEGER, locationLatitude REAL, locationLongitude REAL, locationAccuracy REAL, eventPosted BOOLEAN)";
			DATABASE_TABLECREATEEVENTPARAMETER = "CREATE TABLE IF NOT EXISTS [$TABLENAME] (_id INTEGER PRIMARY KEY, eventId INTEGER, eventName TEXT, eventValue TEXT)";

			DATABASE_CREATEPROFILE = "INSERT INTO [$TABLENAME] ('sdkType', 'sdkVersion', 'applicationId', 'applicationType', 'applicationChannel', 'applicationVersion', 'userId', 'sessionRestartTime', 'connectionType', 'isRoaming', 'locationSource', 'locationAltitude', 'locationLatitude', 'locationLongitude', 'locationAccuracy', 'operator', 'operatorName', 'operatorCountryIso', 'simOperator', 'simCardSerial', 'device', 'model', 'hardwareId', 'version', 'pin', 'operatorConnectionType', 'profilePosted') VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			DATABASE_CREATEEVENT = "INSERT INTO [$TABLENAME] ('profileId', 'eventName', 'eventDetail', 'eventValue', 'errorId', 'eventTime', 'eventLocalTime', 'connectionType', 'operatorConnectionType', 'errorLevel', 'eventPosted') VALUES(?,?,?,?,?,?,?,?,?,?,?)";
			DATABASE_CREATEEVENTPARAMETER = "INSERT INTO [$TABLENAME] ('eventId', 'eventName', 'eventValue') VALUES (?,?,?)";
			DATABASE_TABLENAMEPROFILE = "InAppProfiles";
			DATABASE_TABLENAMEEVENT = "InAppEvents";
			DATABASE_TABLENAMEEVENTPARAMETER = "InAppEventParameters";

			DATABASE_COLUMN_PROFILEID = "profileId";
			DATABASE_COLUMN_SDKTYPE = "sdkType";
			DATABASE_COLUMN_SDKVERSION = "sdkVersion";
			DATABASE_COLUMN_APPLICATIONID = "applicationId";
			DATABASE_COLUMN_APPLICATIONTYPE = "applicationType";
			DATABASE_COLUMN_APPLICATIONCHANNEL = "applicationChannel";
			DATABASE_COLUMN_APPLICATIONVERSION = "applicationVersion";
			DATABASE_COLUMN_USERID = "userId";
			DATABASE_COLUMN_SESSIONRESTARTTIME = "sessionRestartTime";
			DATABASE_COLUMN_CONNECTIONTYPE = "connectionType";
			DATABASE_COLUMN_ISROAMING = "isRoaming";
			DATABASE_COLUMN_LOCATIONSOURCE = "locationSource";
			DATABASE_COLUMN_LOCATIONALTITUDE = "locationAltitude";
			DATABASE_COLUMN_LOCATIONLATITUDE = "locationLatitude";
			DATABASE_COLUMN_LOCATIONLONGITUDE = "locationLongitude";
			DATABASE_COLUMN_LOCATIONACCURACY = "locationAccuracy";
			DATABASE_COLUMN_OPERATOR = "operator";
			DATABASE_COLUMN_OPERATORNAME = "operatorName";
			DATABASE_COLUMN_OPERATORCOUNTRYISO = "operatorCountryIso";
			DATABASE_COLUMN_SIMOPERATOR = "simOperator";
			DATABASE_COLUMN_SIMCARD_SERIAL = "simCardSerial";
			DATABASE_COLUMN_DEVICE = "device";
			DATABASE_COLUMN_MODEL = "model";
			DATABASE_COLUMN_HARDWAREID = "hardwareId";
			DATABASE_COLUMN_VERSION = "version";
			DATABASE_COLUMN_PIN = "pin";
			DATABASE_COLUMN_OPERATORCONNECTIONTYPE = "operatorConnectionType";
			DATABASE_COLUMN_EVENTID = "eventId";
			DATABASE_COLUMN_EVENTNAME = "eventName";
			DATABASE_COLUMN_EVENTDETAIL = "eventDetail";
			DATABASE_COLUMN_EVENTVALUE = "eventValue";
			DATABASE_COLUMN_ERRORID = "errorId";
			DATABASE_COLUMN_EVENTTIME = "eventTime";
			DATABASE_COLUMN_EVENTLOCALTIME = "eventLocalTime";
			DATABASE_COLUMN_ERRORLEVEL = "errorLevel";
	}
	BangoConstants::~BangoConstants()
	{

	}


